package com.lenovo.smarttraffic.ui.activity;

import android.content.Loader;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.JsonRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;
import com.lenovo.smarttraffic.R;
import com.lenovo.smarttraffic.bean.GongJiaoBean_7;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

public class Activity_4_5 extends AppCompatActivity {
    private ImageView icon;
    private TextView title;
    private TextView a_4_5_tv1;
    private TextView a_4_5_tv2;
    private TextView a_4_5_tv3;
    private TextView a_4_5_tv4;
    private TextView a_4_5_tv5;
    private TextView a_4_5_tv6;
    private TextView a_4_4_tv2;
    ArrayList arrayList;
    RequestQueue queue;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.a_4_5);
        initView();

        arrayList = getIntent().getStringArrayListExtra("data");
        Log.i("dsadada__++++++__size6",arrayList.size()+"");
//
//        while (arrayList.iterator().hasNext()){
//            Log.i("dsadada________666",arrayList.iterator().next()+"");
//        }

        a_4_5_tv1.setText(arrayList.get(1)+"-"+arrayList.get(2));
        a_4_5_tv2.setText(arrayList.get(6)+"");
        a_4_5_tv3.setText(arrayList.get(7)+"");
        a_4_5_tv4.setText(arrayList.get(8)+"");
        a_4_5_tv5.setText(arrayList.get(9)+"");
        a_4_5_tv6.setText(arrayList.get(5)+"");
    }

    private void initView() {
        queue = Volley.newRequestQueue(Activity_4_5.this);
        icon = (ImageView) findViewById(R.id.icon);
        title = (TextView) findViewById(R.id.title);
        a_4_5_tv1 = (TextView) findViewById(R.id.a_4_5_tv1);
        a_4_5_tv2 = (TextView) findViewById(R.id.a_4_5_tv2);
        a_4_5_tv3 = (TextView) findViewById(R.id.a_4_5_tv3);
        a_4_5_tv4 = (TextView) findViewById(R.id.a_4_5_tv4);
        a_4_5_tv5 = (TextView) findViewById(R.id.a_4_5_tv5);
        a_4_5_tv6 = (TextView) findViewById(R.id.a_4_5_tv6);
        a_4_4_tv2 = (TextView) findViewById(R.id.a_4_4_tv2);
        icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        title.setText("确定订单");

        a_4_4_tv2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setdata();
            }
        });
    }

    private void setdata() {

        JSONObject object = new JSONObject();
        try {
            object.put("UserName", "user1");
            object.put("Id", arrayList.get(0).toString());
            object.put("PhoneNumber", arrayList.get(7).toString());
            object.put("StartSite", arrayList.get(8).toString());
            object.put("EndSite", arrayList.get(9).toString());
            object.put("BusDate", arrayList.get(5).toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        JsonObjectRequest request = new JsonObjectRequest(JsonRequest.Method.POST, "http://192.168.1.107:8088/transportservice/action/SetUserBusLine.do", object, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                try {
                    if(jsonObject.getString("ERRMSG").equals("成功")){
                        Toast.makeText(Activity_4_5.this, "提交成功", Toast.LENGTH_SHORT).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                Toast.makeText(Activity_4_5.this, "提交失败", Toast.LENGTH_SHORT).show();
            }
        });
        queue.add(request);

    }




}
